package com.css.fxfzaqbz.modules.data.controller;

import com.css.fxfzaqbz.base.response.RestResponse;
import com.css.fxfzaqbz.modules.data.entity.IAAssistAnalyse;
import com.css.fxfzaqbz.modules.data.entity.Report;
import com.css.fxfzaqbz.modules.data.service.IAAssistAnalyseService;
import com.css.fxfzaqbz.modules.data.service.ReportService;
import com.css.fxfzaqbz.web.PlatformSessionContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


/**
 * 单个安保辅助对策分析
 */
@RestController
@RequestMapping("/fxfzaqbz/data")
@Slf4j
public class IAAssistAnalyseController {

    @Resource
    IAAssistAnalyseService iaAssistAnalyseService;

    /**
     * 新增 ia 辅助分析报告
     *
     * @param iaAssistAnalyse
     * @return
     */
    @PostMapping("/saveIAAssistAnalyse")
    public RestResponse saveIAAssistAnalyse(@RequestBody IAAssistAnalyse iaAssistAnalyse) {
        RestResponse restResponse = null;

        try {
            String userID = PlatformSessionContext.getUserID();
            iaAssistAnalyse.setAaId(userID);
            restResponse = RestResponse.succeed(iaAssistAnalyseService.saveIAAssistAnalyse(iaAssistAnalyse));
        } catch (Exception e) {
            log.error("新增 ia 辅助分析报告失败", e);
            restResponse = RestResponse.fail("新增 ia 辅助分析报告失败!");
        }
        return restResponse;
    }




    /**
     * 根据 id 查询辅助分析报告
     *
     * @param id 重大活动id信息
     * @return 辅助分析报告列表
     */
    @GetMapping("/getIAAssistAnalyseList/{id}")
    public RestResponse getIAAssistAnalyseList(@PathVariable String id) {
        RestResponse restResponse = null;
        try {
            restResponse = RestResponse.succeed(iaAssistAnalyseService.getIAAssistAnalyseList(id));
        } catch (Exception e) {
            log.error("查询 ia 辅助分析报告失败!", e);
            restResponse = RestResponse.fail("查询 ia 辅助分析报告失败");
        }
        return restResponse;
    }


    /**
     * 根据 id 查询辅助分析报告
     *
     * @param id 报告id
     * @return 辅助分析报告
     */
    @GetMapping("/getIAAssistAnalyseById/{id}")
    public RestResponse getIAAssistAnalyseById(@PathVariable String id) {
        RestResponse restResponse = null;
        try {
            restResponse = RestResponse.succeed(iaAssistAnalyseService.getIAAssistAnalyseById(id));
        } catch (Exception e) {
            log.error("查询 ia 辅助分析报告失败!", e);
            restResponse = RestResponse.fail("查询 ia 辅助分析报告失败");
        }
        return restResponse;
    }


    /**
     * 逻辑删除，修改数据标志位
     *
     * @param ids 报告id列表
     * @return
     */
    @PostMapping("/delIAAssistAnalyses/{ids}")
    public RestResponse delIAAssistAnalyses(@PathVariable("ids") List<String> ids) {
        RestResponse restResponse = null;
        try {
            String userID = PlatformSessionContext.getUserID();
            iaAssistAnalyseService.delIAAssistAnalyses(ids, userID);
            restResponse = RestResponse.succeed();
        } catch (Exception e) {
            log.error("删除 ia 辅助分析报告失败!", e);
            restResponse = RestResponse.fail("删除 ia 辅助分析报告失败!");
        }
        return restResponse;
    }


    @PostMapping("/updateIAAssistAnalys")
    public RestResponse<Report> updateIAAssistAnalys(@RequestBody IAAssistAnalyse iaAssistAnalyse) {
        RestResponse restResponse = null;
        try {
            restResponse = RestResponse.succeed(iaAssistAnalyseService.updateIAAssistAnalys(iaAssistAnalyse));
        } catch (Exception e) {
            log.error("修改 ia 辅助分析报告失败!", e);
            restResponse = RestResponse.fail("修改 ia 辅助分析报告失败!");
        }
        return restResponse;
    }

}
